﻿<%@ Page Title="" Language="C#" MasterPageFile="~/masterpagecuatui.Master" AutoEventWireup="true" CodeBehind="Result.aspx.cs" Inherits="tracnghiemonline2.Result" %>

<%@ Import Namespace="DataAccess" %>
<%@ Import Namespace="System.Linq" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Kết quả - <%=this.title %> - Tiếng nhật thật dễ</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="w3-row page-main-content w3-light-grey">
        <%
            try
            {
                var get_result = new TblResultController().FetchAll().Where(x => x.ResultId == this.id).Single();
                var get_test = new TblTestController().FetchAll().Where(x => x.TestId == get_result.TestId).Single();
                var get_user = new TblUserController().FetchAll().First();
                if (get_result.ResultUser != 0)
                {
                    get_user = new TblUserController().FetchAll().Where(x => x.UserId == get_result.ResultUser).Single();
                }
                var get_cer = new TblCertificateController().FetchAll().Where(x => x.CerId == get_test.TestCertificate).Single();
                var get_test_detail = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId).ToList();
                string cls = "...";
                if (get_user.ClassX != 0 && get_user.ClassX != null)
                {
                    var get_class = new TblClassController().FetchAll().Where(x => x.Id == get_user.ClassX).Single();
                    cls = get_class.ClassName;
                }
        %>
        <div class="w3-col l9 w3-padding">
            <div class="w3-row w3-teal w3-padding w3-hide-small">
                <div class="w3-third">
                    Trình độ:&nbsp;<label><%=get_cer.CerTitle%></label>
                </div>
                <div class="w3-third">
                    Tên bài:&nbsp;<label><%=get_test.TestTitle%></label>
                </div>
                <div class="w3-third">
                    Thời gian làm bài:&nbsp;<label><%=get_test.TestTime%> Phút</label>
                </div>
                <div class="w3-third">
                    <%if (get_result.ResultUser != 0)
                      { %>
                    Họ tên:&nbsp;<label><%=get_user.FullName%></label>
                    <%}
                      else
                      { %>
                    Họ tên:&nbsp;<label>Khách</label>
                    <%} %>
                </div>
                <div class="w3-third">
                    Lớp:&nbsp;<label><%=cls %></label>
                </div>
                <div class="w3-third">
                    Thời gian hoàn thành:&nbsp;<label><%=get_result.ResultTime%> Phút</label>
                </div>

            </div>
            <div class="w3-row w3-teal w3-small w3-padding w3-hide-medium w3-hide-large">
                <div class="w3-half">
                    Trình độ:&nbsp;<label><%=get_cer.CerTitle%></label>
                </div>
                <div class="w3-half">
                    Tên bài:&nbsp;<label><%=get_test.TestTitle%></label>
                </div>
                <div class="w3-half">
                    Thời gian làm bài:&nbsp;<label><%=get_test.TestTime%> Phút</label>
                </div>
                <div class="w3-half">
                    <%if (get_result.ResultUser != 0)
                      { %>
                    Họ tên:&nbsp;<label><%=get_user.FullName%></label>
                    <%}
                      else
                      { %>
                    Họ tên:&nbsp;<label>Khách</label>
                    <%} %>
                </div>
                <div class="w3-half">
                    Lớp:&nbsp;<label><%=cls %></label>
                </div>
                <div class="w3-half">
                    Trả lời đúng:&nbsp;<label><%=get_result.ResultCorrect%>/<%=get_test_detail.Count%></label>
                </div>
                <div class="w3-half">
                    Thời gian hoàn thành:&nbsp;<label><%=get_result.ResultTime%> Phút</label>
                </div>
            </div>

            <div class="task-content w3-row w3-padding w3-white">
                <header class="w3-center w3-padding">
                    <label class="w3-border-teal w3-large" style="border-bottom: 3px solid">Bài làm</label>
                </header>
                <%
                for (int i = 1; i <= get_test_detail.Count; i++)
                {
                %>
                <div id="<%=i%>" class="the-questions w3-row">
                    <div class="question-content w3-row w3-padding">
                        <label class="w3-border-teal" style="border-bottom: 3px solid">Câu&nbsp;<span class="thutu"><%=i%></span>:</label>&nbsp;<%=get_test_detail[i - 1].TestDetailQuestion%>:<br />
                        <%if (get_test_detail[i - 1].TestDetailUrl != "")
                          {
                              string[] temp = new string[20];

                              temp = get_test_detail[i - 1].TestDetailUrl.ToLower().Split('.');
                              string tail = temp[temp.Length - 1];
                              if (tail == "mp3")
                              {
                        %>
                        <p>
                            <audio src="../Content/testdata/Audio/<%=get_test_detail[i - 1].TestDetailUrl%>" controls="controls" />
                        </p>
                        <%
                              }
                              else
                              {
                        %>
                        <p>
                            <img src="../Content/testdata/picture/<%=get_test_detail[i - 1].TestDetailUrl%>" />
                        </p>
                        <%
                              }
                          }
                        %>
                    </div>

                    <%
                          int check = 0;
                          int test_answer = 0;
                          string temp2 = get_result.ResultAnswer;
                          string[] result = new string[temp2.Split(',').Length];
                          var get_ques = new TblQuestionController().FetchAll().Where(x => x.QuestionTestDetail == get_test_detail[i - 1].TestDetailId).ToList();
                          for (int j = 0; j < temp2.Split(',').Length - 1; j++)
                          {
                              int test_id = int.Parse(temp2.Split(',')[j].Split('-')[0]);
                              test_answer = int.Parse(temp2.Split(',')[j].Split('-')[1]);
                              if (test_id == get_test_detail[i - 1].TestDetailId)
                              {
                                  if (test_answer == get_test_detail[i - 1].TestDetailConfirm)
                                      check = 1;
                                  else
                                      check = 2;
                                  break;
                              }
                          }

                          if (check == 0) // không chọn câu trả lời
                          {
                              for (int j = 1; j <= get_ques.Count; j++)
                              {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="1"><%=j%></span>&nbsp;<%=get_ques[j - 1].QuestionName%></p>
                        <span class="pa1 w3-hide-medium w3-hide-small"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%></span>
                    </div>
                    <%          
                              }
                          }%>

                    <%
                    if (check == 1) // trả lời đúng
                    {
                        for (int j = 1; j <= get_ques.Count; j++)
                        {
                            if (get_ques[j - 1].QuestionId == get_test_detail[i - 1].TestDetailConfirm)
                            {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="w3-green">&nbsp;&nbsp;</span>&nbsp;<%=get_ques[j - 1].QuestionName%>&nbsp;<i class="fa fa-check-circle w3-text-green"></i></p>
                        <span class="pa1 w3-hide-medium w3-hide-small w3-green"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%>&nbsp;<i class="fa fa-check-circle"></i></span>
                    </div>
                    <%}
                            else
                            {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="1"><%=j%></span>&nbsp;<%=get_ques[j - 1].QuestionName%></p>
                        <span class="pa1 w3-hide-medium w3-hide-small"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%></span>
                    </div>
                    <%          
                            }
                        }
                    }
                    %>
                    <%
                    if (check == 2) // trả lời sai
                    {
                        for (int j = 1; j <= get_ques.Count; j++)
                        {
                            if (get_ques[j - 1].QuestionId == get_test_detail[i - 1].TestDetailConfirm)
                            {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="1"><%=j%></span>&nbsp;<%=get_ques[j - 1].QuestionName%></p>
                        <span class="pa1 w3-hide-medium w3-hide-small"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%></span>
                    </div>
                    <%}
                            else
                            {
                                if (get_ques[j - 1].QuestionId == test_answer)
                                {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="w3-red">&nbsp;&nbsp;</span>&nbsp;<%=get_ques[j - 1].QuestionName%>&nbsp;<i class="fa fa-times-circle w3-text-red"></i></p>
                        <span class="pa1 w3-hide-medium w3-hide-small w3-red"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%>&nbsp;<i class="fa fa-times-circle"></i></span>
                    </div>
                    <%}
                                else
                                {
                    %>
                    <div class="pa w3-row w3-padding">
                        <p class="pa-res w3-hide-large" style="padding: 2px"><span class="1"><%=j%></span>&nbsp;<%=get_ques[j - 1].QuestionName%></p>
                        <span class="pa1 w3-hide-medium w3-hide-small"><%=j%>.&nbsp;<%=get_ques[j - 1].QuestionName%></span>
                    </div>
                    <%          
                                }
                            }
                        }
                    }
                    %>
                </div>
                <%
                } %>
            </div>
            <%
                string routing = "";
                string[] split = new string[get_test.TestTitle.Split(' ').Length];
                for (int i = 0; i < get_test.TestTitle.Split(' ').Length; i++)
                {
                    routing += get_test.TestTitle.Split(' ')[i];
                    routing += "-";
                }
                routing += get_test.TestId;
            %>
            <div class="w3-row w3-padding w3-center w3-teal">
                <a href="../trac-nghiem/<%=routing %>" style="border: 2px solid white; width: 140px" class="w3-btn w3-teal w3-hover-text-teal w3-hover-white hvr-icon-spin">Làm lại</a>
            </div>
        </div>
        <div class="w3-col l3 w3-padding w3-hide-medium w3-hide-small">
            <div class="w3-light-grey">
                <header class="w3-padding w3-teal w3-center w3-large">Bảng kết quả</header>
                <div class="w3-white">
                    <label class="w3-padding">Trả lời đúng&nbsp;<span class="w3-tag w3-large w3-teal"><%=get_result.ResultCorrect%>/<%=get_test_detail.Count%></span></label>
                    <div class="w3-padding w3-row">
                        <%--<span class="hinhtron w3-green w3-text-green w3-half"></span>--%>
                        <a class="w3-large answers"><span class=" hinhtron w3-green">&nbsp;&nbsp;</span></a><span class="w3-large"> Câu trả lời đúng</span><br />
                        <br />
                        <a class="w3-large answers"><span class=" hinhtron w3-red">&nbsp;&nbsp;</span></a><span class="w3-large"> Câu trả lời sai</span>
                    </div>
                    <div class="the-results w3-padding-left w3-padding-bottom">
                        <%
                for (int i = 1; i <= get_test_detail.Count; i++)
                { 
                        %>
                        <div id="c<%=i%>" class="cau w3-row">
                            <a href="#<%=i%>" class="thutu w3-btn w3-teal w3-col l2 w3-large"><%=i%></a>
                            <%
                    int check = 0;
                    int test_answer = 0;
                    string temp2 = get_result.ResultAnswer;
                    string[] result = new string[temp2.Split(',').Length];
                    var get_ques = new TblQuestionController().FetchAll().Where(x => x.QuestionTestDetail == get_test_detail[i - 1].TestDetailId).ToList();
                    for (int j = 0; j < temp2.Split(',').Length - 1; j++)
                    {
                        int test_id = int.Parse(temp2.Split(',')[j].Split('-')[0]);
                        test_answer = int.Parse(temp2.Split(',')[j].Split('-')[1]);
                        if (test_id == get_test_detail[i - 1].TestDetailId)
                        {
                            if (test_answer == get_test_detail[i - 1].TestDetailConfirm)
                                check = 1;
                            else
                                check = 2;
                            break;
                        }
                    }

                    if (check == 0) // không chọn 
                    {
                        for (int j = 1; j <= get_ques.Count; j++)
                        {
                            
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron"><%=j%></span></a>
                            <%
                        }
                    }

                    if (check == 1) // chọn đúng
                    {
                        for (int j = 1; j <= get_ques.Count; j++)
                        {
                            if (test_answer == get_ques[j - 1].QuestionId)
                            {
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron w3-green w3-text-green"><%=j%></span></a>
                            <%
                            }
                            else
                            {
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron"><%=j%></span></a>
                            <%
                            }
                        }
                    }

                    if (check == 2) //chọn sai
                    {
                        for (int j = 1; j <= get_ques.Count; j++)
                        {
                            if (get_ques[j - 1].QuestionId == get_test_detail[i - 1].TestDetailConfirm)
                            {
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron"><%=j%></span></a>
                            <%}
                            else
                            {
                                if (get_ques[j - 1].QuestionId == test_answer)
                                {
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron w3-red w3-text-red"><%=j%></span></a>
                            <%}
                                else
                                {
                            %>
                            <a class="answers w3-btn w3-light-grey w3-col l2 w3-large"><span class="hinhtron"><%=j%></span></a>
                            <%          
                                      }
                            }
                        }
                    }
                            %>
                        </div>
                        <%
                } %>
                    </div>
                </div>
            </div>
        </div>
        <%}
            catch
            {
                Response.Redirect("~/trang-chu");
            }
        %>
    </div>
    <script src="../Scripts/multiple-choice.js"></script>
</asp:Content>
